<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加排片</title>
    <script src="../../js/vue.js"></script>
    <script src="../../js/axios0.18.js"></script>
</head>
<body>
<div id="app">
    <form @submit.prevent="submitForm">
        选择电影：
        <select v-model="selMovieId">
            <option value="0">--请选择--</option>
            <option v-for="item in movieList" :value="item.movieId">
                {{item.movieName}}
            </option>
        </select><br>
        选择影厅：
        <select v-model="selHouseId">
            <option value="0">--请选择--</option>
            <option v-for="item in houseList" :value="item.chId">
                {{item.chName}}
            </option>
        </select><br>
        选择开始时间：
        <input type="datetime-local" v-model="startTime" required><br>
        票价：
        <input type="number" v-model="money" required><br>
        <input type="submit" value="添加排片">
    </form>
</div>

</body>
</html>
<script>
    new Vue({
        el: "#app",
        data: {
            selMovieId: 0,
            selHouseId: 0,
            movieList: [],
            houseList: [],
            startTime: '',
            money: ''
        },
        methods: {
            getMovieList() {
                let _this = this;
                axios.post("http://localhost:8080/ssm/cinema/getMovieList")
                    .then(function (resp) {
                        console.log(resp.data);
                        if (resp.data.code === 200) {
                            _this.movieList = resp.data.data;
                        } else {
                            alert(resp.data.msg);
                        }
                    });
            },
            getHouseList() {
                let _this = this;
                axios.post("http://localhost:8080/ssm/cinema/getHouseList")
                    .then(function (resp) {
                        console.log(resp.data);
                        if (resp.data.code === 200) {
                            _this.houseList = resp.data.data;
                        } else {
                            alert(resp.data.msg);
                        }
                    });
            },
            submitForm() {
                const formData = new FormData();
                formData.append("movieId", this.selMovieId);
                formData.append("houseId", this.selHouseId);
                formData.append("startTime", this.startTime);
                formData.append("money", this.money);
                axios.post("http://localhost:8080/ssm/cinema/addArrange",
                    formData).then(function (resp) {
                    console.log(resp.data);
                    if (resp.data.code === 200) {
                        alert("添加成功")
                        window.location = "home.html";
                    } else {
                        alert(resp.data.msg);
                    }
                });
            }
        },
        mounted() {
            this.getMovieList();
            this.getHouseList();
        }
    })
</script>

